

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.feature.hetero_feature_binning.base_feature_binning &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.feature.hetero_feature_binning.base_feature_binning</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.feature.hetero_feature_binning.base_feature_binning</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>

<span class="c1">#</span>
<span class="c1">#  Copyright 2019 The FATE Authors. All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1">#  you may not use this file except in compliance with the License.</span>
<span class="c1">#  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#  Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1">#  See the License for the specific language governing permissions and</span>
<span class="c1">#  limitations under the License.</span>

<span class="kn">from</span> <span class="nn">google.protobuf</span> <span class="k">import</span> <span class="n">json_format</span>

<span class="kn">from</span> <span class="nn">arch.api.proto</span> <span class="k">import</span> <span class="n">feature_binning_meta_pb2</span><span class="p">,</span> <span class="n">feature_binning_param_pb2</span>
<span class="kn">from</span> <span class="nn">arch.api.utils</span> <span class="k">import</span> <span class="n">log_utils</span>
<span class="kn">from</span> <span class="nn">federatedml.feature.binning.base_binning</span> <span class="k">import</span> <span class="n">IVAttributes</span>
<span class="kn">from</span> <span class="nn">federatedml.feature.binning.bucket_binning</span> <span class="k">import</span> <span class="n">BucketBinning</span>
<span class="kn">from</span> <span class="nn">federatedml.feature.binning.quantile_binning</span> <span class="k">import</span> <span class="n">QuantileBinning</span>
<span class="kn">from</span> <span class="nn">federatedml.model_base</span> <span class="k">import</span> <span class="n">ModelBase</span>
<span class="kn">from</span> <span class="nn">federatedml.param.feature_binning_param</span> <span class="k">import</span> <span class="n">FeatureBinningParam</span>
<span class="kn">from</span> <span class="nn">federatedml.statistic.data_overview</span> <span class="k">import</span> <span class="n">get_header</span>
<span class="kn">from</span> <span class="nn">federatedml.util</span> <span class="k">import</span> <span class="n">abnormal_detection</span>
<span class="kn">from</span> <span class="nn">federatedml.util</span> <span class="k">import</span> <span class="n">consts</span>
<span class="kn">from</span> <span class="nn">federatedml.util.transfer_variable.hetero_feature_binning_transfer_variable</span> <span class="k">import</span> \
    <span class="n">HeteroFeatureBinningTransferVariable</span>

<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">log_utils</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span>

<span class="n">MODEL_PARAM_NAME</span> <span class="o">=</span> <span class="s1">&#39;FeatureBinningParam&#39;</span>
<span class="n">MODEL_META_NAME</span> <span class="o">=</span> <span class="s1">&#39;FeatureBinningMeta&#39;</span>


<div class="viewcode-block" id="BaseHeteroFeatureBinning"><a class="viewcode-back" href="../../../../federatedml.feature.hetero_feature_binning.html#federatedml.feature.hetero_feature_binning.base_feature_binning.BaseHeteroFeatureBinning">[docs]</a><span class="k">class</span> <span class="nc">BaseHeteroFeatureBinning</span><span class="p">(</span><span class="n">ModelBase</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Do binning method through guest and host</span>

<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    header : list</span>
<span class="sd">        record headers of input table</span>

<span class="sd">    has_synchronized : bool</span>
<span class="sd">        Record whether the encryption information has been synchronized or not.</span>

<span class="sd">    flowid : str</span>
<span class="sd">        Use in cross validation</span>

<span class="sd">    binning_result: dict</span>
<span class="sd">        Record binning result of guest party. The format is {&#39;col_name&#39;: &#39;iv_attr&#39;, ... }</span>

<span class="sd">    host_results: dict</span>
<span class="sd">        This attribute uses to record host results. For future version which may record multiple host results,</span>
<span class="sd">        the format is dict of dict.</span>
<span class="sd">        e.g.</span>
<span class="sd">        host_results = {&#39;host1&#39;: {&#39;x1&#39;: iv1, &#39;x2: iv2}</span>
<span class="sd">                        &#39;host2&#39;: ...</span>
<span class="sd">                        }</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">BaseHeteroFeatureBinning</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transfer_variable</span> <span class="o">=</span> <span class="n">HeteroFeatureBinningTransferVariable</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cols</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cols_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">binning_obj</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">header</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">schema</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">has_synchronized</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flowid</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">binning_result</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c1"># dict of iv_attr</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">host_results</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c1"># dict of host results</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">party_name</span> <span class="o">=</span> <span class="s1">&#39;Base&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model_param</span> <span class="o">=</span> <span class="n">FeatureBinningParam</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">_init_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">params</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model_param</span> <span class="o">=</span> <span class="n">params</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cols_index</span> <span class="o">=</span> <span class="n">params</span><span class="o">.</span><span class="n">cols</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">QUANTILE</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">binning_obj</span> <span class="o">=</span> <span class="n">QuantileBinning</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">party_name</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">BUCKET</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">binning_obj</span> <span class="o">=</span> <span class="n">BucketBinning</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">party_name</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># self.binning_obj = QuantileBinning(self.bin_param)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Binning method: </span><span class="si">{}</span><span class="s2"> is not supported yet&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">method</span><span class="p">))</span>

<div class="viewcode-block" id="BaseHeteroFeatureBinning.transform"><a class="viewcode-back" href="../../../../federatedml.feature.hetero_feature_binning.html#federatedml.feature.hetero_feature_binning.base_feature_binning.BaseHeteroFeatureBinning.transform">[docs]</a>    <span class="k">def</span> <span class="nf">transform</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_instances</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_parse_cols</span><span class="p">(</span><span class="n">data_instances</span><span class="p">)</span>
        <span class="n">transform_cols_idx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">transform_param</span><span class="o">.</span><span class="n">transform_cols</span>
        <span class="n">transform_type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">transform_param</span><span class="o">.</span><span class="n">transform_type</span>
        <span class="n">data_instances</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">binning_obj</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">data_instances</span><span class="p">,</span> <span class="n">transform_cols_idx</span><span class="p">,</span> <span class="n">transform_type</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">set_schema</span><span class="p">(</span><span class="n">data_instances</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="n">data_instances</span>

        <span class="k">return</span> <span class="n">data_instances</span></div>

    <span class="k">def</span> <span class="nf">_get_meta</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">col_list</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cols</span><span class="p">]</span>

        <span class="n">meta_protobuf_obj</span> <span class="o">=</span> <span class="n">feature_binning_meta_pb2</span><span class="o">.</span><span class="n">FeatureBinningMeta</span><span class="p">(</span>
            <span class="n">method</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">method</span><span class="p">,</span>
            <span class="n">compress_thres</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">compress_thres</span><span class="p">,</span>
            <span class="n">head_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">head_size</span><span class="p">,</span>
            <span class="n">error</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">error</span><span class="p">,</span>
            <span class="n">bin_num</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">bin_num</span><span class="p">,</span>
            <span class="n">cols</span><span class="o">=</span><span class="n">col_list</span><span class="p">,</span>
            <span class="n">adjustment_factor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">adjustment_factor</span><span class="p">,</span>
            <span class="n">local_only</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="o">.</span><span class="n">local_only</span><span class="p">,</span>
            <span class="n">need_run</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">need_run</span>
        <span class="p">)</span>
        <span class="k">return</span> <span class="n">meta_protobuf_obj</span>

    <span class="k">def</span> <span class="nf">_get_param</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="n">binning_result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">binning_result</span>

        <span class="n">host_results</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">host_results</span>

        <span class="n">iv_attrs</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">col_name</span><span class="p">,</span> <span class="n">iv_attr</span> <span class="ow">in</span> <span class="n">binning_result</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">iv_result</span> <span class="o">=</span> <span class="n">iv_attr</span><span class="o">.</span><span class="n">result_dict</span><span class="p">()</span>
            <span class="n">iv_object</span> <span class="o">=</span> <span class="n">feature_binning_param_pb2</span><span class="o">.</span><span class="n">IVParam</span><span class="p">(</span><span class="o">**</span><span class="n">iv_result</span><span class="p">)</span>
            <span class="n">iv_attrs</span><span class="p">[</span><span class="n">col_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">iv_object</span>
        <span class="n">binning_result_obj</span> <span class="o">=</span> <span class="n">feature_binning_param_pb2</span><span class="o">.</span><span class="n">FeatureBinningResult</span><span class="p">(</span><span class="n">binning_result</span><span class="o">=</span><span class="n">iv_attrs</span><span class="p">)</span>

        <span class="n">final_host_results</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">host_id</span><span class="p">,</span> <span class="n">this_host_results</span> <span class="ow">in</span> <span class="n">host_results</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">host_result</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">host_col_idx</span><span class="p">,</span> <span class="n">iv_attr</span> <span class="ow">in</span> <span class="n">this_host_results</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">iv_result</span> <span class="o">=</span> <span class="n">iv_attr</span><span class="o">.</span><span class="n">result_dict</span><span class="p">()</span>
                <span class="n">iv_object</span> <span class="o">=</span> <span class="n">feature_binning_param_pb2</span><span class="o">.</span><span class="n">IVParam</span><span class="p">(</span><span class="o">**</span><span class="n">iv_result</span><span class="p">)</span>
                <span class="n">host_result</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">host_col_idx</span><span class="p">)]</span> <span class="o">=</span> <span class="n">iv_object</span>
            <span class="n">final_host_results</span><span class="p">[</span><span class="n">host_id</span><span class="p">]</span> <span class="o">=</span> <span class="n">feature_binning_param_pb2</span><span class="o">.</span><span class="n">FeatureBinningResult</span><span class="p">(</span><span class="n">binning_result</span><span class="o">=</span><span class="n">host_result</span><span class="p">)</span>

        <span class="n">result_obj</span> <span class="o">=</span> <span class="n">feature_binning_param_pb2</span><span class="o">.</span><span class="n">FeatureBinningParam</span><span class="p">(</span><span class="n">binning_result</span><span class="o">=</span><span class="n">binning_result_obj</span><span class="p">,</span>
                                                                   <span class="n">host_results</span><span class="o">=</span><span class="n">final_host_results</span><span class="p">)</span>
        <span class="n">json_result</span> <span class="o">=</span> <span class="n">json_format</span><span class="o">.</span><span class="n">MessageToJson</span><span class="p">(</span><span class="n">result_obj</span><span class="p">)</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;json_result: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">json_result</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">result_obj</span>

    <span class="k">def</span> <span class="nf">_load_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model_dict</span><span class="p">):</span>
        <span class="n">model_param</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">model_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;model&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">MODEL_PARAM_NAME</span><span class="p">)</span>
        <span class="c1"># self._parse_need_run(model_dict, MODEL_META_NAME)</span>
        <span class="n">model_meta</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">model_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;model&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">MODEL_META_NAME</span><span class="p">)</span>
        <span class="c1"># model_meta.cols = list(model_meta.cols)</span>
        <span class="c1"># model_meta.transform_param.transform_cols = list(model_meta.transform_param.transform_cols)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cols</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">model_meta</span><span class="o">.</span><span class="n">cols</span><span class="p">))</span>
        <span class="n">bin_method</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">model_meta</span><span class="o">.</span><span class="n">method</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">bin_method</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">QUANTILE</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">binning_obj</span> <span class="o">=</span> <span class="n">QuantileBinning</span><span class="p">(</span><span class="n">model_meta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">party_name</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">binning_obj</span> <span class="o">=</span> <span class="n">BucketBinning</span><span class="p">(</span><span class="n">model_meta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">party_name</span><span class="p">)</span>

        <span class="n">binning_result_obj</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">model_param</span><span class="o">.</span><span class="n">binning_result</span><span class="o">.</span><span class="n">binning_result</span><span class="p">)</span>
        <span class="n">host_params</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">model_param</span><span class="o">.</span><span class="n">host_results</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">binning_result</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">host_results</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">col_name</span><span class="p">,</span> <span class="n">iv_attr_obj</span> <span class="ow">in</span> <span class="n">binning_result_obj</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">iv_attr</span> <span class="o">=</span> <span class="n">IVAttributes</span><span class="p">([],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[])</span>
            <span class="n">iv_attr</span><span class="o">.</span><span class="n">reconstruct</span><span class="p">(</span><span class="n">iv_attr_obj</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">binning_obj</span><span class="o">.</span><span class="n">reconstruct_by_iv_obj</span><span class="p">(</span><span class="n">col_name</span><span class="p">,</span> <span class="n">iv_attr</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">binning_result</span><span class="p">[</span><span class="n">col_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">iv_attr</span>
            <span class="c1"># self.cols.append(col_name)</span>

        <span class="k">for</span> <span class="n">host_name</span><span class="p">,</span> <span class="n">host_result_obj</span> <span class="ow">in</span> <span class="n">host_params</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">host_result_obj</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">host_result_obj</span><span class="o">.</span><span class="n">binning_result</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">col_name</span><span class="p">,</span> <span class="n">iv_attr_obj</span> <span class="ow">in</span> <span class="n">host_result_obj</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">iv_attr</span> <span class="o">=</span> <span class="n">IVAttributes</span><span class="p">([],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[])</span>
                <span class="n">iv_attr</span><span class="o">.</span><span class="n">reconstruct</span><span class="p">(</span><span class="n">iv_attr_obj</span><span class="p">)</span>
                <span class="n">host_result_obj</span><span class="p">[</span><span class="n">col_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">iv_attr</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">host_results</span><span class="p">[</span><span class="n">host_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">host_result_obj</span>
        <span class="c1"># LOGGER.debug(&quot;In feature binning load model, self.binning_result: {}, cols: {}, host_results: {}&quot;.format(</span>
        <span class="c1">#     self.binning_result, self.cols, self.host_results</span>
        <span class="c1"># ))</span>

<div class="viewcode-block" id="BaseHeteroFeatureBinning.export_model"><a class="viewcode-back" href="../../../../federatedml.feature.hetero_feature_binning.html#federatedml.feature.hetero_feature_binning.base_feature_binning.BaseHeteroFeatureBinning.export_model">[docs]</a>    <span class="k">def</span> <span class="nf">export_model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_output</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_output</span>

        <span class="n">meta_obj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_meta</span><span class="p">()</span>
        <span class="n">param_obj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_param</span><span class="p">()</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">{</span>
            <span class="n">MODEL_META_NAME</span><span class="p">:</span> <span class="n">meta_obj</span><span class="p">,</span>
            <span class="n">MODEL_PARAM_NAME</span><span class="p">:</span> <span class="n">param_obj</span>
        <span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model_output</span> <span class="o">=</span> <span class="n">result</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="BaseHeteroFeatureBinning.save_data"><a class="viewcode-back" href="../../../../federatedml.feature.hetero_feature_binning.html#federatedml.feature.hetero_feature_binning.base_feature_binning.BaseHeteroFeatureBinning.save_data">[docs]</a>    <span class="k">def</span> <span class="nf">save_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span></div>

<div class="viewcode-block" id="BaseHeteroFeatureBinning.set_flowid"><a class="viewcode-back" href="../../../../federatedml.feature.hetero_feature_binning.html#federatedml.feature.hetero_feature_binning.base_feature_binning.BaseHeteroFeatureBinning.set_flowid">[docs]</a>    <span class="k">def</span> <span class="nf">set_flowid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flowid</span><span class="o">=</span><span class="s2">&quot;samole&quot;</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flowid</span> <span class="o">=</span> <span class="n">flowid</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transfer_variable</span><span class="o">.</span><span class="n">set_flowid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flowid</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">_parse_cols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_instances</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span>

        <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Before Binning, schema is : </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data_instances</span><span class="o">.</span><span class="n">schema</span><span class="p">))</span>
        <span class="n">header</span> <span class="o">=</span> <span class="n">get_header</span><span class="p">(</span><span class="n">data_instances</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">schema</span> <span class="o">=</span> <span class="n">data_instances</span><span class="o">.</span><span class="n">schema</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">header</span> <span class="o">=</span> <span class="n">header</span>
        <span class="c1"># LOGGER.debug(&quot;data_instance count: {}, header: {}&quot;.format(data_instances.count(), header))</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cols_index</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">header</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Cannot get feature header, please check input data&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cols</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">header</span><span class="p">))]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># cols = []</span>
            <span class="c1"># for idx in self.cols_index:</span>
            <span class="c1">#     try:</span>
            <span class="c1">#         idx = int(idx)</span>
            <span class="c1">#     except ValueError:</span>
            <span class="c1">#         raise ValueError(&quot;In binning module, selected index: {} is not integer&quot;.format(idx))</span>
            <span class="c1">#</span>
            <span class="c1">#     if idx &gt;= len(header):</span>
            <span class="c1">#         raise ValueError(</span>
            <span class="c1">#             &quot;In binning module, selected index: {} exceed length of data dimension&quot;.format(idx))</span>
            <span class="c1">#     cols.append(header[idx])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cols_index</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">cols_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cols</span><span class="p">:</span>
            <span class="n">col_name</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="n">col</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cols_dict</span><span class="p">[</span><span class="n">col_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">col</span>

<div class="viewcode-block" id="BaseHeteroFeatureBinning.set_schema"><a class="viewcode-back" href="../../../../federatedml.feature.hetero_feature_binning.html#federatedml.feature.hetero_feature_binning.base_feature_binning.BaseHeteroFeatureBinning.set_schema">[docs]</a>    <span class="k">def</span> <span class="nf">set_schema</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_instance</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">schema</span><span class="p">[</span><span class="s1">&#39;header&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span>
        <span class="n">data_instance</span><span class="o">.</span><span class="n">schema</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">schema</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;After Binning, when setting schema, schema is : </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data_instance</span><span class="o">.</span><span class="n">schema</span><span class="p">))</span></div>


    <span class="k">def</span> <span class="nf">_abnormal_detection</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_instances</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Make sure input data_instances is valid.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">abnormal_detection</span><span class="o">.</span><span class="n">empty_table_detection</span><span class="p">(</span><span class="n">data_instances</span><span class="p">)</span>
        <span class="n">abnormal_detection</span><span class="o">.</span><span class="n">empty_feature_detection</span><span class="p">(</span><span class="n">data_instances</span><span class="p">)</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>